/**
 * Created by 李柏霖
 * 2020/10/18 20:49
 */

package com.lbl.Controller;

import com.lbl.domain.Department;
import com.lbl.domain.Employee;
import com.lbl.service.IDepartmentService;
import com.lbl.service.IEmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import java.util.List;

@Controller
@RequestMapping("/employee")
public class EmployeeController {

    @Autowired
    private IEmployeeService employeeService;

    @RequestMapping(path = "/list",method = {RequestMethod.GET,RequestMethod.POST})
    public String list(Model model){
        System.out.println("employee....list.....run");
        //显示所有的person数据
        List<Employee> employeeList = employeeService.findAll();
        System.out.println(employeeList);
        model.addAttribute("employeeList",employeeList);
        return "list";
    }

    @RequestMapping(path = "/delete",method = {RequestMethod.GET,RequestMethod.POST})
    public String delete(Integer eid){
        System.out.println("employee....delete.....run");
        //显示所有的person数据
        employeeService.deleteById(eid);
        return "redirect:list";
    }


    @RequestMapping(path = "/updateUI",method = {RequestMethod.GET,RequestMethod.POST})
    public String updateUI(Integer eid,Model model){
        System.out.println("employee....updateUI.....run");
        //显示所有的person数据
        Employee employee = employeeService.findById(eid);
        model.addAttribute("employee",employee);
        return "updateUI";
    }

    @RequestMapping(path = "/update",method = {RequestMethod.GET,RequestMethod.POST})
    public String update(Employee employee){
        System.out.println("employee....update.....run");
        //显示所有的person数据
        employeeService.update(employee);
        return "redirect:list";
    }
}
